public class MathHelper {

	/**
	 * 
	 * @param a
	 * @param b
	 * @param c
	 * @return
	 */
	public static double getTriangleArea(int a, int b, int c) {
		double area = -1;
		double p;
		if (a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a) {
			p = (a + b + c) / 2;
			area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
		}
		return area;
	}

	/**
	 * 用异常类处理 Java 的异常有两个父类 Exception,runtime异常和checked异常-- checked异常必须进行处理
	 * 
	 * checkedException
	 * 
	 * @param a
	 * @param b
	 * @param c
	 * @return
	 * @throws Exception
	 */
	public static double getTriangleAreaE(double a, double b, double c)
			throws Exception {
		double area = -1;
		double p;
		if (a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a) {
			p = (a + b + c) / 2;
			area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
		} else {
			Exception exception = new Exception("参数错误,无法构成三角形!");
			throw exception;
		}

		return area;
	}

	/**
	 * 用异常类处理 Java 的异常有两个父类 Exception,runtime异常和checked异常-- checked异常必须进行处理
	 * 
	 * runtimeException
	 * 
	 * @param a
	 * @param b
	 * @param c
	 * @return
	 */
	public static double getTriangleArea(double a, double b, double c) {
		double area = -1;
		double p;
		if (a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a) {
			p = (a + b + c) / 2;
			area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
		} else {
			RuntimeException exception = new RuntimeException("参数错误,无法构成三角形!");
			throw exception;
		}

		return area;
	}

	/**
	 * 用异常类处理 Java 的异常有两个父类 Exception,runtime异常和checked异常-- checked异常必须进行处理
	 * 
	 * 自定义的TriangleException
	 * 
	 * @param a
	 * @param b
	 * @param c
	 * @return
	 * @throws TriangleException
	 */
	public static double getTriangleAreaC(double a, double b, double c)
			throws TriangleException {
		double area = -1;
		double p;
		if (a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a) {
			p = (a + b + c) / 2;
			area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
		} else {
			TriangleException exception = new TriangleException();
			throw exception;
		}

		return area;
	}
}
